<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment("用户id")->index();
            $table->unsignedBigInteger('merchant_id')->comment("商户id")->index();
            $table->unsignedBigInteger('channel_id')->comment("通道id");
            $table->string('status')->comment("订单状态");
            $table->string('refund_status')->default(\App\Models\Order::REFUND_STATUS_PENDING)->comment('退款状态');
            $table->string('from_url')->comment("来源域名");
            $table->string('title')->comment('标题');
            $table->string('trade_no')->comment('平台交易编号')->unique();
            $table->string('out_trade_no')->comment('商户交易编号')->unique();
            $table->decimal('total_amount')->default(0)->comment('订单金额');
            $table->decimal('pay_amount')->default(0)->comment('支付金额');
            $table->string('gateway')->comment('支付网关');
            $table->string('pay_user')->nullable()->comment('支付人信息');
            $table->string('payment_no')->nullable()->comment('支付交易id')->index();
            $table->timestamp('paid_at')->nullable()->comment('支付时间');
            $table->unsignedInteger('client_ip')->default(0)->comment('客户ip');

            $table->string('notify_url')->nullable()->comment('通知地址');
            $table->string('return_url')->nullable()->comment('回跳地址');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
